package aspect.example;
import aspect.util.Angles;
import aspect.entity.behavior.Behavior;
import static aspect.core.AspectLauncher.*;
import aspect.core.AspectRenderer;
import static aspect.core.AspectRenderer.*;
import static aspect.core.AspectRenderer.GeometryType.QUADS;
import aspect.entity.Entity;
import aspect.entity.Player;
import aspect.physics.Time;
import aspect.render.FrameBuffer;
import static aspect.resources.Resources.*;
import aspect.util.Vector3;
import aspect.render.Material;
import aspect.render.Texture;
import aspect.render.Mesh;
import aspect.render.ViewModel;
import aspect.render.shader.Shader;
import aspect.render.shader.Shader.Type;
import aspect.render.shader.ShaderProgram;
import aspect.util.Vector2;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JWindow;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.GL11;
public class ShaderDemo extends Behavior {
private Entity cube;
private Entity pipe;
private Entity player;
private ShaderProgram shader1;
private ShaderProgram shader2;
private FrameBuffer frameBuffer;
private Vector3 lightPos = Vector3.zero();
public static void main(String[] args) {
run(800, 600, false, 60, new ShaderDemo());
}
@Override
public void onAdd() {
printGlVersion();
player = new Player(Vector3.zero());
Material material = new Material(Texture.create(UNLOADED_IMAGE));
cube = new Entity(box(material, 0.9f, 0.7f, 0.6f));
cube.pos = new Vector3(-1, 0, -4);
cube.ang.pitch = -20;
pipe = new Entity(pipe(material, 0.5f, 2, 60));
pipe.pos = new Vector3(1, 0, -4);
Shader vertex = new Shader(new File("shaders/example.vert"), Type.VERTEX);
Shader fragment1 = new Shader(new File("shaders/example1.frag"), Type.FRAGMENT);
Shader fragment2 = new Shader(new File("shaders/example2.frag"), Type.FRAGMENT);
shader1 = new ShaderProgram(vertex, fragment1);
shader2 = new ShaderProgram(vertex, fragment2);
try {
frameBuffer = new FrameBuffer(128, 128, DEFAULT_CAMERA);
} catch (Exception ex) {
Logger.getLogger(ShaderDemo.class.getName()).log(Level.SEVERE, null, ex);
}
}
@Override
public void update() {
player.update();
shader2.setVar("time", Time.frameTime());
cube.ang.yaw += 1;
//pipe.ang.yaw += 0.5f;
lightPos.x += 1;
if (lightPos.x > 10) {
lightPos.x = 0;
}
}
@Override
public void render() {
shader2.bind();
cube.render();
shader2.unbind();
shader1.bind();
pipe.render();
shader1.unbind();
}
}